package com.jcp.service.imple;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jcp.dao.UsersMapper;
import com.jcp.entity.Users;
import com.jcp.service.UserService;
import com.jcp.util.LayuiData;
import com.jcp.util.MD5Util;
import com.jcp.util.PageData;

import tk.mybatis.mapper.entity.Example;

/**
 * 登录界面的UserService接口的实现类
 * 
 * @author 朱耿封
 *
 */
@Service
public class UserServiceImple implements UserService {
	// UsersMapper的依赖注入
	@Autowired
	private UsersMapper um;

	/**
	 * 登录界面登录方法
	 */

	public Users LoginUser(Users user) {

//		String pwd = user.getPassword();		
//		pwd = MD5Util.getEncodeByMd5(pwd);
//		user.setPassword(pwd);


		Users users = um.selectOne(user);
		return users;
	}

	/**
	 * 登录界面注册方法
	 */
	@Override
	public boolean ZhuCheUser(Users users) {
		// TODO Auto-generated method stub

//		String pwd = users.getPassword();
//		pwd = MD5Util.getEncodeByMd5(pwd);
//		users.setPassword(pwd);

		System.out.println(users.getPassword());
		return um.insertUsers(users) > 0;
	}

	public boolean selectChong(Users users) {
		List<Users> list = um.selectChong(users);
		if (list.size() != 0) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public LayuiData<Users> selUserMessageByPage(int page, int pageSize, String strLike) {
		// TODO Auto-generated method stub
		strLike = "%" + strLike + "%";
		PageHelper.startPage(page, pageSize);
		Example example = new Example(Users.class);
		example.createCriteria().andLike("userName", strLike);
		List<Users> users = um.selectByExample(example);
		PageInfo<Users> pageInfo = new PageInfo<Users>(users);
		LayuiData<Users> layuiData = new LayuiData<>(0, "", (int) pageInfo.getTotal(), pageInfo.getList());
		return layuiData;
	}

	@Override
	public LayuiData<Users> selCarMessageByPage(int page, int pageSize, String strLike) {
		// TODO Auto-generated method stub
		strLike = "%" + strLike + "%";
		PageHelper.startPage(page, pageSize);
		Example example = new Example(Users.class);
		example.createCriteria().andLike("carNumber", strLike);
		List<Users> users = um.selectByExample(example);
		PageInfo<Users> pageInfo = new PageInfo<Users>(users);
		LayuiData<Users> layuiData = new LayuiData<>(0, "", (int) pageInfo.getTotal(), pageInfo.getList());
		return layuiData;
	}

	@Override
	public boolean updUserMessage(String carNumber, String userName, String phoneNumber, String password,
			double remainder, String membership_expires_date, String carModel, String carColor) {
		// TODO Auto-generated method stub
		Users users = new Users(carNumber, userName, password, phoneNumber, remainder, membership_expires_date,
				carModel, carColor);

		return um.updateByPrimaryKeySelective(users) > 0;
	}

	@Override
	public int selectCountEnterCar(String time) {
		// TODO Auto-generated method stub
		return um.selectCountEnterCar(time + "%");
	}

	@Override
	public int selectCountOutCar(String time) {
		// TODO Auto-generated method stub
		return um.selectCountOutCar(time + "%");
	}

	@Override
	public int addparmt(String payment_amount, String carNumber) {
		// TODO Auto-generated method stub
		return um.addparmt(payment_amount, carNumber);
	}

	@Override
	public int addparmt1(String payment_amount, String carNumber) {
		// TODO Auto-generated method stub
		return um.addparmt1(payment_amount, carNumber);
	}
	@Override
	public Users selectByOne(Users users) {
		// TODO Auto-generated method stub
		
		return um.selectLogin(users);
	}
}
